/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 * 作者:张谦
 */

import React, {FC} from "react";
import permissionService from "@/pages/sys/permission/service";
import {Tree} from "antd";
import styles from "@/pages/sys/role/components/Authorize.less";
import useLoad from "@/hooks/useLoad";

const HavePermissions: FC<{ primaryKey: string }> = (props) => {
  const {primaryKey} = props;
  const {data: members = []} = useLoad<[]>({
    isLoad: Boolean(primaryKey),
    onLoad: () => permissionService.selectUserPermissionModules(primaryKey)
  }, [primaryKey]);


  return (
    <div style={{margin: '0 24px 0 0'}}>
      {members.length ? (
        <Tree
          style={{padding: "10px 5px", overflowY: 'auto'}}
          showIcon
          defaultExpandAll
          treeData={members}
        />
      ) : (<div className={`${styles.alert} ${styles.warning} ${styles.margin} ${styles.padding}`}>未配置</div>)}
    </div>
  )
}

export default HavePermissions;
